package com.itheima.service.impl;

import com.itheima.mapper.DeptMapper;
import com.itheima.pojo.Dept;
import com.itheima.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class DeptServiceImpl implements DeptService {

    @Autowired
    private DeptMapper deptMapper;
    @Override
    public List<Dept> findAll() {
        return deptMapper.findAll() ;
    }

    @Override
    public void deleteById(Integer id) {
        deptMapper.deleteById(id);
    }

    //添加部门
    @Override
    public void add(Dept dept) {
        //获取修改时间和创建时间
        dept.setCreateTime(LocalDateTime.now());
        dept.setUpdateTime(LocalDateTime.now());
        //调用mapper层添加
        deptMapper.insert(dept);

    }

    //查询部门
    @Override
    public Dept getbyid(Integer id) {
        //获取部门信息
       Dept dept = deptMapper.getbyid(id);
        return dept;
    }

    @Override
    public void update(Dept dept) {
        //获取修改时间
        dept.setUpdateTime(LocalDateTime.now());
        //调用mapper层修改
        deptMapper.update(dept);
    }

    /**
     * 修改部门信息
     */

}
